﻿using System;
using System.Collections.Generic;
using System.Data.Common;
using System.Linq;
using System.Text;
using Tilver.Data;
using Weixin.MP.DAL.WeixinMP;

namespace Weixin.MP.BLL.AppUser
{

    public class AppUserBO
    {
        private AppUserInfoMO _mo;
        public AppUserBO()
        {
            _mo = new AppUserInfoMO();
        }

        #region 查询
        public AppUserInfoEO GetByOpenId(string openId, TransactionManager tm = null)
        {
            return _mo.SelectByPK(openId, tm);
        }

        public List<AppUserInfoEO> GetAppUsers(int pageSize, int pageIndex, ref long recordCount)
        {
            var sqlWhere = new StringBuilder();
            sqlWhere.Append(" 1=1 ");
            var paras = new List<DbParameter>();
            return _mo.SelectPager(sqlWhere.ToString(), " [openid] ASC ", paras, pageSize, pageIndex, ref recordCount);
        }

        #endregion
        #region 修改
        public void EditAppUserInfo(AppUserInfoEO eo, TransactionManager tm = null)
        {
            _mo.Update(eo, tm);
        }
        #endregion
        #region 添加

        public void AddAppUserInfo(AppUserInfoEO eo, TransactionManager tm = null)
        {
            _mo.Insert(eo, tm);
        }
        #endregion
        #region 删除

        public void DelAppUserInfo(string openId, TransactionManager tm = null)
        {
            _mo.DeleteByPK(openId, tm);
        }
        #endregion
        #region 添加或更新
        public void AddOrEdit(AppUserInfoEO eo, TransactionManager tm = null)
        {
            if (GetByOpenId(eo.Openid, tm) == null)
            {
                AddAppUserInfo(eo, tm);
            }
        }
        #endregion
    }
}
